package youkeda;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class FileUploadServer {

    public static void main(String[] args) throws IOException {

        ServerSocket serverSocket=new ServerSocket(8888);
        //得到接收信息
        Socket accept = serverSocket.accept();
        InputStream inputStream = accept.getInputStream();
        File file=new File("D:\\upload");
        if (!file.exists()){
            file.mkdir();
        }
        byte[] bytes=new byte[1024];
        int len=0;
        FileOutputStream fileOutputStream=new FileOutputStream(file+"\\1.png");
        //将得到的信息传入文件夹的指定位置
        while ((len=inputStream.read(bytes))!=-1){
            fileOutputStream.write(bytes,0,len);
        }
        //返回给客户端信息
        accept.getOutputStream().write("已经成功收到".getBytes());

        inputStream.close();
        fileOutputStream.close();
        serverSocket.close();
    }
}
